import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'

// Element Plus 全局配置
const elementPlusConfig = {
  locale: zhCn,
  size: 'default',
  zIndex: 3000,
  // 添加全局配置以避免DOM访问问题
  namespace: 'el',
  // 禁用某些可能导致问题的特性
  button: {
    autoInsertSpace: false
  }
}

// 安装插件的函数
export function setupElementPlus(app) {
  // 添加全局警告处理
  const originalWarnHandler = app.config.warnHandler
  
  app.config.warnHandler = (msg, vm, trace) => {
    // 忽略Element Plus的已知警告
    if (msg && (
      msg.includes('label act as value is about to be deprecated') ||
      msg.includes('Invalid prop: validation failed for prop "size"') ||
      msg.includes('Property "Search" was accessed during render') ||
      msg.includes('getComputedStyle') ||
      msg.includes('parameter 1 is not of type')
    )) {
      // 静默处理这些警告
      return
    }
    
    // 调用原始警告处理器
    if (originalWarnHandler) {
      originalWarnHandler(msg, vm, trace)
    } else {
      console.warn('Vue warning:', msg, trace)
    }
  }
  
  try {
    // 安装Element Plus
    app.use(ElementPlus, elementPlusConfig)
    // Element Plus 安装成功
  } catch (error) {
    console.error('Element Plus 安装失败:', error)
  }
}

export default ElementPlus 